module ProcessQueue.Test exposing (..)

import ProcessQueue.Queue as Q
import ProcessQueue.Model exposing (..)
import Array as A
import Html as H
import ProcessQueue.Writter as W exposing ((>>=))


test_inner_pcb : H.Html msg
test_inner_pcb = 
 case Q.inner_pcb 0 0 Q.mock_queue of
    Nothing -> H.text "Nothing"
    Just pcb -> H.text (Q.print_pcb pcb)

test_with_new_process : H.Html msg
test_with_new_process =
 Q.view (Q.with_new_process Q.mock_queue (PCB "new_pcb" 99 1))

test_process : H.Html msg
test_process = 
 Q.view (Q.process 0 Q.mock_queue)

test_remove_point_pcb : H.Html msg
test_remove_point_pcb =
  let (maybe_pcb,queue) = Q.remove_point_pcb 0 Q.mock_queue
      pcb_view = 
        case maybe_pcb of
          Nothing -> H.text "pcb: Nothing"
          Just pcb -> H.text ("pcb: " ++ Q.print_pcb pcb)
      queue_view = Q.view queue
  in  H.div [] [pcb_view,queue_view]




my_mock_queue : Queue
my_mock_queue = A.fromList [A.fromList [PCB "mock" 100 0],A.fromList [PCB "mock2" 99 1]]


my_mock_queue2 : Queue
my_mock_queue2 = A.fromList [A.fromList [PCB "mock" 100 0,PCB "mock2" 99 1]]

test_point_pcb_down : H.Html msg
test_point_pcb_down =
  Q.view (Q.point_pcb_down 0 my_mock_queue2)

test_writter : H.Html msg
test_writter =
  let wc = (W.Writter 0 ["Here 0"]) >>= (\x -> W.Writter (x+1) ["Add 1"])
      logs = W.runLog wc
      log = List.foldl (\cur acc -> acc ++ cur) "" logs
  in H.text log



main : H.Html msg
main = test_writter
  